package net.zubara.esni.core.client;

import net.zubara.esni.core.CorePlugin;
import net.zubara.esni.core.util.EFacebookParam;
import net.zubara.esni.core.util.EFacebookUrl;
import net.zubara.esni.core.util.EPermission;
import net.zubara.esni.core.util.FacebookUtil;
import net.zubara.esni.core.util.UrlFactory;

public class FacebookClient extends AbstractRestClient {

	public static String AUTHENTICATION_URL;
	static {
		String apiKey = (String) CorePlugin.getDefault().getConfigProperties().get("facebook.api.key");
		EPermission[] perms = new EPermission[] { EPermission.READ_STREAM, EPermission.PUBLISH_STREAM, EPermission.OFFLINE_ACCESS };
		String permsParam = FacebookUtil.getPermissionParam(perms);

		String url = UrlFactory.init(EFacebookUrl.FB_LOGIN_URL.value())
			.param(EFacebookParam.API_KEY.value(), apiKey)
			.param(EFacebookParam.CONNECT_DISPLAY.value(), "popup")
			.param(EFacebookParam.V.value(), "1.0")
			.param(EFacebookParam.NEXT.value(), EFacebookUrl.FB_CONNECT_SUCCESS_URL.value())
			.param(EFacebookParam.CANCEL_URL.value(), EFacebookUrl.FB_CONNECT_FAILURE_URL.value())
			.param(EFacebookParam.FBCONNECT.value(), "true")
			.param(EFacebookParam.RETURN_SESSION.value(), "true")
			.param(EFacebookParam.SESSION_KEY_ONLY.value(), "true")
			.param(EFacebookParam.REQ_PERMS.value(), permsParam)
			.create();

		AUTHENTICATION_URL = url;
	}

	@Override
	protected String initUri() {
		return (String) CorePlugin.getDefault().getConfigProperties().get("facebook.api.uri");
	}

}
